<?php

error_reporting(E_ALL & ~E_NOTICE);
ini_set("display_errors",1);

    if (!class_exists("Config"))    include_once '../config/classes/class.Config.php';
    $cfg = new config();
    
    if (!class_exists("InfoElem"))      include_once $cfg->pathClasses."/class.InfoElem.php";
    
    $id = $_GET['id'];
    
    $elem = new Infoelem($id);
    $elem->getFromBDById();
    
    /*Si el elemento no existe....*/
    if (!$elem->getLat()) 
    {
        include_once $cfg->pathBackEnd."/header_sinlinks.php";
        echo "Error recuperando el elemento $id<br>";
        exit();
    }
    
?>
<head>
    
    <title>ElectrolinerasOnline.com</title>         

    <!-- META -->
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=8">

    <!-- CSS -->
    <link rel="stylesheet" type="text/css" media="all" href="<?php echo $cfg->pathCss ?>/main2.css"/>      
    <link href='http://fonts.googleapis.com/css?family=Nunito:300' rel='stylesheet' type='text/css'> <!-- 'Nunito', sans-serif; -->
    <link href='http://fonts.googleapis.com/css?family=Convergence' rel='stylesheet' type='text/css'> <!-- 'Convergence', sans-serif; -->
    <link type="text/css" href="<?php echo $cfg->pathJs ?>/jqueryui/css/custom-theme/jquery-ui-1.8.17.custom.css" rel="stylesheet" />	
<!--    <link type="text/css" href="<?php echo $cfg->pathJs ?>/DropKick/dropkick.css" rel="stylesheet" />	-->
<!--    <link type="text/css" href="<?php echo $cfg->pathJs ?>/DropKick/example/example.css" rel="stylesheet" />	-->
    <link type="text/css" href="<?php echo $cfg->pathCss ?>/ezmark.css" rel="stylesheet" />	
    <link rel="stylesheet" href="<?php echo $cfg->pathJs ?>/fancybox/source/jquery.fancybox.css?v=2.0.5" type="text/css" media="screen" />
    <link rel="stylesheet" href="<?php echo $cfg->pathJs ?>/fancybox/source/helpers/jquery.fancybox-buttons.css?v=2.0.5" type="text/css" media="screen" />
    <link rel="stylesheet" href="<?php echo $cfg->pathJs ?>/fancybox/source/helpers/jquery.fancybox-thumbs.css?v=2.0.5" type="text/css" media="screen" />

    <!-- SCRIPTS -->
    <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
    <script type="text/javascript" src="<?php echo $cfg->pathJs ?>/jqueryui/js/jquery-1.7.1.min.js"></script>
    <script type="text/javascript" src="<?php echo $cfg->pathJs ?>/jqueryui/js/jquery-ui-1.8.17.custom.min.js"></script>
    <script type="text/javascript" src="<?php echo $cfg->pathJs ?>/common.js"></script>
<!--    <script type="text/javascript" src="<?php echo $cfg->pathJs ?>/DropKick/jquery.dropkick-1.0.0.js"></script>-->
    <script type="text/javascript" src="<?php echo $cfg->pathJs ?>/jquery.ezmark.min.js"></script>
    <script type="text/javascript" src="<?php echo $cfg->pathJs ?>/fancybox/source/jquery.fancybox.pack.js?v=2.0.5"></script>
    <script type="text/javascript" src="<?php echo $cfg->pathJs ?>/fancybox/lib/jquery.mousewheel-3.0.6.pack.js"/></script>
    <script type="text/javascript" src="<?php echo $cfg->pathJs ?>/fancybox/source/helpers/jquery.fancybox-buttons.js?v=2.0.5"></script>
    <script type="text/javascript" src="<?php echo $cfg->pathJs ?>/fancybox/source/helpers/jquery.fancybox-thumbs.js?v=2.0.5"></script>
   
    <script>   
        var id = "<?php echo $id ?>";
        
        function checkElem(){
           
            if (document.new_elem_form.nombre.value == ""){
                alert("El campo nombre no puede estar vacio");
                document.new_elem_form.nombre.focus();
                return 0;
            }
            
            if (document.new_elem_form.lat.value == ""){
                alert("El campo lat no puede estar vacio");
                document.new_elem_form.lat.focus();
                return 0;
            }
            
            if (document.new_elem_form.lng.value == ""){
                alert("El campo lng no puede estar vacio");
                document.new_elem_form.lng.focus();
                return 0;
            }

            if (document.new_elem_form.precio.value == ""){
                alert("El campo precio no puede estar vacio");
                document.new_elem_form.precio.focus();
                return 0;
            }
        
            if (document.new_elem_form.direccion.value == ""){
                alert("Introduce la direccion porfavor.");
                document.new_elem_form.direccion.focus();
                return 0;
            }
                               
             
            if (!isNumber(document.new_elem_form.precio.value)) {
                alert("El campo precio debe ser un valor decimal");
                document.new_elem_form.precio.value = "";
                document.new_elem_form.precio.focus();
                return 0;
            }
            
            if (!isNumber(document.new_elem_form.lat.value)) {
                alert("El campo lat debe ser un valor decimal");
                document.new_elem_form.lat.focus();
                return 0;
            }
            
            if (!isNumber(document.new_elem_form.lng.value)) {
                alert("El campo lng debe ser un valor decimal");
                document.new_elem_form.lng.focus();
                return 0;
            }
           
            
            document.new_elem_form.submit();
           
        }
        
              
        $(document).ready(function() {
            //escondemos la imagen del elemento, para mostrarla al hacer click sobre la lupa.
            $("#img_edit_elem").hide();
            
            $("#zoom_button").click( function() {
                if ($("#img_edit_elem").is(":hidden")) {
                    $("#img_edit_elem").slideDown("slow"); 
                }else{
                    $("#img_edit_elem").slideUp("slow"); 
                    
                }
              
            });
            
            $("#btn_delete").click( function () {
                       
                   var html = "<div style='margin:0px auto;'>" +
                                "<table align=center>"+
                                    "<form name=form_confirm action='<?php echo $cfg->pathElems?>/delete_elem_exec.php' method=POST>" +
                                        "<tr><td> <span style='color:red; text-shadow: 1px 3px 1px lightGrey; '>"+
                                        "¿Quiere eliminar el elemento <strong>" + id + "</strong> ? </span><br><br></td></tr> " +
                                        "<tr><td style='text-align:center'>"+
                                        "<input type=hidden name=id value='" + id + "'/>" +  
                                        "<input type=button value=SI onclick='document.form_confirm.submit()'/>" +
                                        "<input type=button value=NO onclick='$.fancybox.close()'/></tr></td>" +
                                    "</form>"+
                                "</table>" +
                              "</div>";
                   
                   openFancyBox(html,"","","");
            });
        });
        
        
    </script>
    
    

</head>


            <body>
    <div id="contenedor_admin" class="container">

        <?php
            include $cfg->pathBackEnd."/header_sinlinks.php";
            //include "menu.php";
        ?>
           

        <div id="cuerpo" class="clear">
                
                <div  id="edit_elem">
                        <form name="new_elem_form" method="post" action="edit_elem_exec.php" enctype="multipart/form-data">
                            <input type="hidden" value="<?php echo $id ?>" name="id"/>
                            <table style="text-align: left" align="center">

                                <tr>
                                    <td colspan="2">
                                        <h3>Modificar electrolinera</h3>
                                    </td>
                                </tr>            
                                <tr>
                                    <td class="texto"> ID: </td>
                                    <td> <input readonly style="width: auto" id="id" name="id" type="text" maxlength="4" value="<?php echo $elem->getId() ?>"/> </td>
                                </tr>
                                <tr>
                                    <td class="texto">  Nombre  </td>
                                    <td> <input style="width: auto" id="nombre" name="nombre" type="text" maxlength="50" value="<?php echo $elem->getNombre() ?>"/> </td>
                                </tr>
                                <tr>
                                    <td class="texto">  Lat  </td>
                                    <td> <input style="width: auto" id="lat" name="lat" type="text" maxlength="20" value="<?php echo $elem->getLat() ?>"/>  </td>
                                </tr>
                                <tr>
                                    <td class="texto">  Lng </td>
                                    <td> <input style="width: auto" id="lng" name="lng" type="text" maxlength="20" value="<?php echo $elem->getLng() ?>"/>  </td>
                                </tr>
                                <tr>
                                    <td class="texto">  Precio  </td>
                                    <td> <input style="width: 50px" id="precio" name="precio" type="text" maxlength="4" value="<?php echo $elem->getPrecio() ?>"/> &euro; </td>
                                </tr>

                                <tr>
                                    <td class="texto">  Direccion </td>
                                    <td>  <input style="width: 250px" id="direccion" name="direccion" type="text" maxlength="100" value="<?php echo $elem->getDireccion() ?>"/> </td>
                                </tr>
                                <tr>
                                    <td class="texto">
                                        <div id="zoom_button">
                                                <img src="<?php echo $cfg->pathImg.'/zoom.png'; ?>"/>     Foto: 
                                        </div>
                                    </td>
                                    <td class="texto">
                                        <input id="foto" name="foto" type="file" maxlength="50"/>
                                    </td>
                                </tr>

                                <tr>
                                    <td colspan="2">
                                        <img id="img_edit_elem" class="img_standart" src="<?php echo $cfg->pathElems.'/img/'.$elem->getFoto() ?>"/>
                                        <input type="hidden" value="<?php echo $elem->getFoto() ?>" name="foto_old" id="foto_old"/>
                                    </td>
                                </tr>    

                                <tr>
                                    <td class="texto">
                                            <p>Comentario</p>
                                    </td>
                                </tr>
                                <tr>
                                    <td colspan="2">
                                            <textarea name="comentario" style="height:100px; width: 350px;">
                                                <?php echo $elem->getComentario() ?>
                                            </textarea>
                                    </td>
                                </tr>

                                <tr>
                                    <td colspan="2" style="border-top:1px dotted #6a0">                           
                                        <select name="estado" id="estado">
                                            <option value="0" <?php if ($elem->getEstado() == "0") echo "selected" ?> > Desactivado </option>
                                            <option value="1" <?php if ($elem->getEstado() == "1") echo "selected" ?> > Activo </option>
                                            <option value="2" <?php if ($elem->getEstado() == "2") echo "selected" ?> > Pendiente </option>
                                            <option value="3" <?php if ($elem->getEstado() == "3") echo "selected" ?> > Averiado </option>
                                            <option value="4" <?php if ($elem->getEstado() == "4") echo "selected" ?> > Otros </option>
                                        </select>

                                    </td>
                                </tr>

                                <tr>
                                    <td>
                                        <input style="margin-top: 20px" type="button" id="btn_new_elem" value="Enviar" onClick="checkElem()"/>
                                    </td>
                                    <td>
                                        <input style="margin-top: 20px" type="button" id="btn_close" value="Cancelar" onClick="window.close()"/>
                                        <input style="margin-top: 20px" type="button" id="btn_delete" value="Borrar" onClick=""/>
                                    </td>
                                </tr>


                            </table>
                        </form>
                </div>
          

        </div>
        
        <div id="hidden_variables" class="oculto">
            
            <!-- En este bloque metemos el contenido del fancybox -->
                      
                 
            <?php //include $cfg->pathConfig."/users/add_new_elem.php"?>
            
            <div id="aux_hidden_div">
                
            </div>
        </div>

    </div>
</body>


